# 1.公交车(Bus)包含类型(type_name),座位数(seat_count)
# 2.乘客类(Person),拥有名字属性
# 3.公交车支持上(add_bus)下(sub_bus)车,要求修改乘客列表(member_list)
# 4.上下乘客后,要求打印输出车辆信息:类型,座位数,乘客列表
class Person(object):
    def __init__(self, name):
        self.name = name


xm = Person("小明")
xh = Person("小红")
xl = Person("小李")


class Bus(object):

    def __init__(self, type_name, seat_count):
        self.type_name = type_name
        self.seat_count = seat_count
        self.member_list = []

    def add_bus(self, person):
        if self.seat_count > 0:
            self.seat_count -= 1
            self.member_list.append(person.name)
        else:
            print("没有空余座位,无法上车")

    def sub_bus(self, person):
        if person.name in self.member_list:
            self.seat_count += 1
            self.member_list.remove(person.name)
        else:
            print("乘客不存在")

    def __str__(self):
        return f"车辆类型:{self.type_name}," \
               f"剩余座位数{self.seat_count}," \
               f"乘客列表为:{self.member_list}"


bmw = Bus("宝马", 5)
bmw.add_bus(xm)
print(bmw)
bmw.add_bus(xh)
print(bmw)
bmw.sub_bus(xm)
print(bmw)
bmw.sub_bus(xm)
print(bmw)
bmw.add_bus(xl)
print(bmw)
